﻿using System;
using Lintop.ePos.Common.DataAccess;

namespace PowerToolsWeb.DataAccess
{
    public partial class Tpt_Product : DataAccessBase
    {
        //TODO: 请把你的方法添加在这里
    }

    public partial class Tpt_ProductCollection : DataAccessCollectionBase
    {
        //TODO: 请把你的方法添加在这里
        /// <summary>
        /// 列出商品列表
        /// </summary>
        /// <param name="typeid"></param>
        /// <param name="productName"></param>
        /// <returns></returns>
        public bool ListProduct(int typeid, string productName)
        {
            string sql = @"SELECT p.*,ty.TypeName
                            FROM Tpt_Product p,Tpt_ProductType ty
                           where p.TypeID = ty.TypeID";
            if (typeid != -1)
            {
                sql += " and p.typeId=" + typeid;
            }
            if (!string.IsNullOrEmpty(productName))
            {
                sql += " and p.ProductName like '%" + productName + "%'";
            }
            sql += " order by p.CREATTIME desc";
            return ListBySql(sql);
        }
        /// <summary>
        /// 取首页推荐商品（前八条）
        /// </summary>
        /// <returns></returns>
        public bool ListRecommend()
        {
            string sql = @"select p.PRODUCTID,p.PRODUCTNAME,p.PICURL 
                            from Tpt_Product p 
                            where p.ISRECOMMEND=1 
                            order by CREATTIME desc 
                            limit 0,8";
            return ListBySql(sql);
        }
        public bool ListProductForList(int typeid, string productName)
        {
            string sql = @"SELECT p.PRODUCTID,p.PRODUCTNAME,p.PICURL
                            FROM Tpt_Product p
                           where 1=1";
            if (typeid != -1)
            {
                sql += " and p.typeId=" + typeid;
            }
            if (!string.IsNullOrEmpty(productName))
            {
                sql += " and p.ProductName like '%" + productName + "%'";
            }
            sql += " order by p.CREATTIME desc";
            return ListBySql(sql);
        }
    }
}
